//
//  ViewController.m
//  ceshi
//
//  Created by MB.Lee on 17/1/11.
//  Copyright © 2017年 com.coubi.ii. All rights reserved.
//

#import "ViewController.h"
#import "NSDate+DateExtension.h"

@interface ViewController ()



@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    
   NSString *name = @"2017-1-12 16:59:35";
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSDate *date = [fmt dateFromString:name];
    
    NSLog(@"%d",date.isThisYear);
    NSLog(@"%d",date.isToday);
    NSLog(@"%d",date.isYesterday);
    
    NSDateComponents *cmps = [NSDate detaleFromDate:date];
    NSLog(@"%@",cmps);
    
    
    [self judgeDateState:date];
    
    
    
 }
-(void)judgeDateState:(NSDate *)date{
    NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
    
    
    
    if (date.isThisYear) {
        if (date.isToday) {
            NSCalendar *calendar = [NSCalendar currentCalendar];
            NSCalendarUnit unit = NSCalendarUnitHour|NSCalendarUnitSecond|NSCalendarUnitMinute;
           NSDateComponents *cmps =   [calendar components:unit fromDate:date toDate:[NSDate date] options:0];
            if (cmps.hour>=1) {
               
                NSLog(@"%ld",cmps.hour);
            }else if (cmps.minute>=1){
                NSLog(@"%ld分钟以前",cmps.minute);
            }else{
                NSLog(@"刚刚");
            }
  
            
        }else if (date.isYesterday){
            fmt.dateFormat = @"昨天 HH:mm:ss";
            NSString *nameString = [fmt stringFromDate:date];
            NSLog(@"%@",nameString);
        }else{
            fmt.dateFormat = @"yyyy-MM-dd HH:mm:ss";
            NSString *dateString = [fmt stringFromDate:date];
            NSLog(@"--%@",dateString);
        }
    }else{
        NSLog(@"---%@",date);
    }
    
    
}





/*
 @interface NSDate : NSObject <NSCopying, NSSecureCoding>
 
 @property (readonly) NSTimeInterval timeIntervalSinceReferenceDate;
 
 - (instancetype)init NS_DESIGNATED_INITIALIZER;
 - (instancetype)initWithTimeIntervalSinceReferenceDate:(NSTimeInterval)ti NS_DESIGNATED_INITIALIZER;
 - (nullable instancetype)initWithCoder:(NSCoder *)aDecoder NS_DESIGNATED_INITIALIZER;
 
 @end
 
 @interface NSDate (NSExtendedDate)
 
 - (NSTimeInterval)timeIntervalSinceDate:(NSDate *)anotherDate;
 @property (readonly) NSTimeInterval timeIntervalSinceNow;
 @property (readonly) NSTimeInterval timeIntervalSince1970;
 
 - (id)addTimeInterval:(NSTimeInterval)seconds NS_DEPRECATED(10_0, 10_6, 2_0, 4_0);
 - (instancetype)dateByAddingTimeInterval:(NSTimeInterval)ti NS_AVAILABLE(10_6, 2_0);
 
 - (NSDate *)earlierDate:(NSDate *)anotherDate;
 - (NSDate *)laterDate:(NSDate *)anotherDate;
 - (NSComparisonResult)compare:(NSDate *)other;
 - (BOOL)isEqualToDate:(NSDate *)otherDate;
 
 @property (readonly, copy) NSString *description;
 - (NSString *)descriptionWithLocale:(nullable id)locale;
 
 + (NSTimeInterval)timeIntervalSinceReferenceDate;
 
 @end
 

 */

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
